package dobest.ray.com.jiongjiong.views;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.TextView;

import dobest.ray.com.jiongjiong.R;

/**
 * 边框可变色的textview
 */
public class CornerTextView extends TextView {

    private Paint paint;

    public CornerTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    public CornerTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CornerTextView(Context context) {
        super(context);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setStrokeWidth(2f);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(getResources().getColor(R.color.colorPrimary));
        paint.setAntiAlias(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        initRect(canvas);
        super.onDraw(canvas);
    }

    private void initRect(Canvas canvas) {
        canvas.drawRoundRect(new RectF(1, 1, getWidth() - 1, getHeight() - 1),
                30, 30, paint);
    }

    @Override
    public void setTextColor(int color) {
        paint.setColor(color);
        this.invalidate();
        super.setTextColor(color);
    }
}
